import {
  postForm
}
from '../../utils/request'

Page({

  data: {
    basePath: getApp().globalData.basePath,
  },

  onLoad(options) {
    let id = options.id;
    if (id) {
      this.setData({
        id: id
      })
    }
  },
  onReady() {},
  onShow() {
    this.getGoods().then(id => {
      this.getDetail();
    });
  },
  onHide() {},
  onUnload() {},
  onPullDownRefresh() {},
  onReachBottom() {},
  onShareAppMessage() {},
  getGoods() {
    return new Promise((resove, reject) => {
      if (this.data.id) {
        resove(this.data.id)
        return;
      }
      postForm({
        url: 'front/api/goods/get'
      }).then(resp => {
        this.setData({
          id: resp.id
        })
        resove(this.data.id)
      })
    })
  },
  getDetail() {
    let id = this.data.id;
    let url = 'front/api/goods/detail/' + id;
    postForm({
      url: url
    }).then(target => {
      this.setData({
        target: target
      })
    })
  },
})